package graph;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @Author 26233
 * @Create 2021-04-08 22:35:45
 */

public class GraphNode {

    // direct link edge node
    public GraphNode edgeNode;

    // edge node
    public GraphNode next;
    public int id;

    public Object data;

    // this node to all edge node weight
    public List<int[]> weightList;

    public void addWeight(int edgeId, int weight){
        if (this.weightList == null){
            this.weightList = new ArrayList<>();
        }
        weightList.add(new int[]{edgeId, weight});
    }

    public int[] getMinEdge(Map<Integer, Integer> visited){
        int min = Integer.MAX_VALUE;
        int minIndex = 0;

        for (int i = 0; i < weightList.size(); i++){
            if (visited.get(weightList.get(i)[0]) != 1 && weightList.get(i)[1] < min){
                min = weightList.get(i)[1];
                minIndex = weightList.get(i)[0];
            }
        }
        return new int[]{id, minIndex, min};
    }

    public int[] getMinNode(int[] visited){

        int min = Integer.MAX_VALUE;
        int minIndex = 0;

        GraphNode tempNext = next;

        while (tempNext != null){
            for (int i = 0; i < weightList.size(); i++){
                if(visited[weightList.get(i)[0]] != 1 && weightList.get(i)[1] < min){
                    min = weightList.get(i)[1];
                    minIndex = weightList.get(i)[0];
                }
            }
            tempNext = tempNext.next;
        }
        return new int[]{id, minIndex, min};
    }

    public int[] getWeight(int dst){
        for (int i = 0; i < weightList.size(); i++){
            if(weightList.get(i)[0] == dst){
                return new int[]{dst, weightList.get(i)[1]};
            }
        }
        return new int[]{dst, Integer.MAX_VALUE};
    }
}
